package p.jce;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;

public class RMessageDigest {
	public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException {
		try {
			return getInstance(algorithm, "BC");
		} catch (NoSuchProviderException e) {
			throw new RuntimeException(e);
		}
	}

	public static MessageDigest getInstance(String algorithm, String provider) throws NoSuchAlgorithmException,
			NoSuchProviderException {
		if ("BC".equals(provider)) {
			try {
				return BC.newInstance("MessageDigest", algorithm);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return MessageDigest.getInstance(algorithm, provider);
	}

	public static MessageDigest getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException {
		return getInstance(algorithm);
	}

}
